<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<script>

// 通过数组来实现栈


class Stack {
  constructor() {
    this.items = []
    this.length = this.items.length
  }
  push(node) {
    this.items.push(node)  // push向数组末尾添加元素（进栈方法）
  }
  pop() {
    this.items.pop()  // 弹出栈最末尾的元素（出栈方法）
  }
  peek() {
    return this.items[this.items.length - 1]  // 获取栈最末尾元素的
  }
  isEmpty() {
    return this.items.length === 0  // 判断栈是否为空
  }
  clear() {
    this.items = []
  }
}

const stack = new Stack()
stack.push({a: 1})
console.log(stack)

</script>


<body>
</body>
</html>